###############################################################
#
# Targets:
#		all	-	build and install  
#		clean	-	clean everything
#
# This makefile uses the following environment variables:
#
#   PALMTOOLSU - path to directory where palm tools should go.
#       ex: "/usr/local/PalmTools"
#
#	
# Conventions:
#	 "ALLUPPER"  case variable names are generally exported or provided by
#				        the environment
#	 "initLower" case variables are local to the makefile
#
#
# Commonly used  Automatic Variables:
#	  $< represents the first dependency
#	  $^ represents all dependencies
#	  $? represents all dependencies that are newer than the target
#	  $@ represents the target 
#
#
###################################################################

# ====================================================
# Include the common Make variables for PalmOS executables
# ====================================================
# This one is constant
include $(PALMTOOLSU)/bin/Palm-DefaultVars.make

# This one can be modified for different build options
#  and is optional 
-include $(PALMTOOLSU)/bin/Palm-CustomVars.make

PILRC             = /usr/local/palmdev/bin/pilrc
OBJRES            = /usr/local/palmdev/bin/obj-res

# The shell to use
SHELL		  = /bin/sh

# Directory paths
objDir		  = ../Obj
srcDir		  = ../Src
rscDir		  = ../Rsc
testsDir	  = ../Tests
cardIncsDir	  = ../../../Libs/Incs

# Target info

include $(srcDir)/VFSMark.make

# These are fake targets used to perform certain actions. Use the .PHONY
#  command to make sure they don't get confused with actual filenames
.PHONY : all install clean help 

# Set the default install directory if not passed down to us
#  from the parent makefile
ifndef InstallDir
  InstallDir = $(PALMTOOLSU)/bin/Device
endif

#############################################################
# Master Builds
#############################################################
all: 	$(objDir)/$(progFile).prc

install:   
	cp $(objDir)/$(progFile).prc $(InstallDir)

clean:
	rm -f *.bin
	rm -f *.grc
	rm -f $(objDir)/*


#############################################################
# Implicit build rules
#############################################################
$(objDir)/%.o :  $(srcDir)/%.c
	$(CC) $(CFLAGS) -c $< -o $@

#############################################################
# Program Build
#############################################################

# ------------------------------------------------------------
# Link and combine with resources. 
# change the --type appl to a -L for libraries
# ------------------------------------------------------------
$(objDir)/$(progFile).prc: $(objList) \
                          $(rscDir)/$(progFile).rcp
	$(CC) $(CFLAGS) $(objList) -o $(objDir)/$(progFile)
	$(PILRC) -q -I $(rscDir) $(rscDir)/$(progFile).rcp
	$(OBJRES) $(objDir)/$(progFile)
	$(PALMRC) --output $(objDir)/$(progFile).prc \
                  --creator $(progCreator) \
                  --type appl \
                  --name $(progName) \
                  --version-number 1.1 \
                  *.grc *.bin
	rm -f *.bin *.grc
